package com.entrogy.bean;

import com.entrogy.utils.constants.ErrorEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用的返回的类
 * @author lxj
 */
public class Msg {
	
	//状态码(为在ErrorEnum中定义的错误码)
	private Enum code;
	
	//提示信息
	private String msg;
	
	//用户要返回给浏览器的数据
	private Map<String, Object> data = new HashMap<String, Object>();

	public static Msg success(){
		Msg result = new Msg();
		result.setCode(ErrorEnum.E_100);
		result.setMsg(ErrorEnum.E_100.getErrorMsg());
		return result;
	}
	
	public static Msg fail(Enum code, String msg){
		Msg result = new Msg();
		result.setCode(code);
		result.setMsg(msg);
		return result;
	}
	
	public Msg add(String key,Object value){
		this.getData().put(key, value);
		return this;
	}
	
	public Enum getCode() {
		return code;
	}

	public void setCode(Enum code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}
	
	
}
